import string
import dbcommand
from google.appengine.ext import db

#enter this

alphabet = "abcdefghijklmnopqrstuvwxyz 1234567890"


def encode(word, value):
    assert value, value
    keys = 'abcdefghijklmnopqrstuvwxyz 0123456789'
    values = value
    encoding = {}
    assert len(values) >= len(keys), (values, keys)
    for i, key in enumerate(keys):
        encoding[key] = values[i]
    words = word.lower()
    new_words = ""
    for letter in words:
        if letter in alphabet:
            new_words = new_words + encoding[letter]
        else:
            new_words = new_words + letter
    return new_words

def decode(word, value):
    assert value, value
    keys = 'abcdefghijklmnopqrstuvwxyz 01234567890'
    values = value
    encoding = {}
    assert len(values) >= len(keys), (values, keys)
    for i, key in enumerate(values):
        encoding[key] = keys[i]
    new_words = ""
    words = word.lower()
    for letter in words:
        if letter in alphabet:
            new_words = new_words + encoding[letter]
        else:
            new_words = new_words + letter
    return new_words
